﻿#pragma once
#include "SimpleSynth.h"

#include "Enveloper.h"
#include "interpolator/Interpolator.h"


namespace yzrilyzr_simplesynth{
	ECLASS(TimeEnvelop, public NoteProcessor), public Enveloper{
	private:
		std::shared_ptr<yzrilyzr_interpolator::Interpolator> curve;
		u_time duration;
		bool inv;
		/**
		 * @param curve
		 * @param duration (ms)
		 */
	public:
		TimeEnvelop() : TimeEnvelop(0,nullptr,false){
			registerParamTimeMs("Time(ms)", &duration);
		}
		TimeEnvelop(u_time_ms duration,std::shared_ptr<yzrilyzr_interpolator::Interpolator> curve) : TimeEnvelop(duration,curve,false){}
		TimeEnvelop(u_time_ms duration,std::shared_ptr<yzrilyzr_interpolator::Interpolator> curve,bool inv){
			this->curve=curve;
			this->duration=duration/1000.0;
			this->inv=inv;
		}
		u_sample getAmp(Note &note)override{
			u_time x=note.passedTime/duration;
			x=yzrilyzr_util::Util::clamp01(x);
			if(inv) x=1-x;
			return curve->y(x);
		}
	};
}